package cn.star.jots.employee.controller;

import cn.star.jots.base.response.JsonResult;
import cn.star.jots.employee.pojo.dto.EmployeeLoginParam;
import cn.star.jots.employee.pojo.dto.EmployeeQuery;
import cn.star.jots.employee.pojo.dto.EmployeeSaveParam;
import cn.star.jots.employee.pojo.dto.EmployeeSavePassword;
import cn.star.jots.employee.pojo.vo.EmployeeVO;
import cn.star.jots.employee.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/employee")
@Api(tags = "员工管理")
@Slf4j
public class EmployeeController {
    @Autowired
    EmployeeService employeeService;

    @PostMapping("/login")
    @ApiOperation(value = "用户登录")
    public JsonResult login(EmployeeLoginParam employeeLoginParam) {
        log.info("用户登录:userLoginParam={}", employeeLoginParam);
        EmployeeVO employeeVO = employeeService.login(employeeLoginParam);
        return JsonResult.ok(employeeVO);
    }

    @PostMapping("/backup")
    @ApiOperation(value = "备用登录")
    public JsonResult backup(EmployeeLoginParam employeeLoginParam) {
        log.info("备用登录:userLoginParam={}", employeeLoginParam);
        EmployeeVO employeeVO = employeeService.backup(employeeLoginParam);
        return JsonResult.ok(employeeVO);
    }

    @GetMapping("/select")
    @ApiOperation(value = "查询员工信息")
    public JsonResult selectAll(EmployeeQuery employeeQuery){
        log.info("查询员工信息:employeeQuery={}", employeeQuery);
        List<EmployeeVO> list = employeeService.selectAll(employeeQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("/save")
    @ApiOperation(value = "保存员工信息")
    public JsonResult saveInfo(EmployeeSaveParam employeeSaveParam){
        log.info("保存员工信息:employeeVO={}", employeeSaveParam);
        employeeService.saveInfo(employeeSaveParam);
        return JsonResult.ok();
    }

    @PutMapping("/update/status/{id}/{status}")
    @ApiOperation(value = "更新员工状态")
    public JsonResult updateStatus(@PathVariable Long id, @PathVariable String status){
        log.info("更新员工状态:id={},status={}", id, status);
        employeeService.updateStatus(id, status);
        return JsonResult.ok();
    }

    @PutMapping("/update/password/{id}")
    @ApiOperation(value = "重置员工密码")
    public JsonResult updatePassword(@PathVariable Long id){
        log.info("重置员工密码:id={}", id);
        employeeService.updatePassword(id);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除员工")
    public JsonResult delete(@PathVariable Long id){
        log.info("删除员工信息:id={}", id);
        employeeService.delete(id);
        return JsonResult.ok();
    }

    @DeleteMapping("/delete/batch/{ids}")
    @ApiOperation(value = "批量删除员工")
    public JsonResult deleteBatch(@PathVariable List<Long> ids){
        log.info("批量删除员工信息:ids={}", ids);
        employeeService.deleteBatch(ids);
        return JsonResult.ok();
    }

    @PutMapping("/savePassword")
    @ApiOperation(value = "修改密码")
    public JsonResult updateSavePassword(EmployeeSavePassword employeeSavePassword){
        log.info("修改密码:employeeSavePassword={}", employeeSavePassword);
        employeeService.savePassword(employeeSavePassword);
        return JsonResult.ok();
    }
}
